
* Set directories
cd /Users/byrned/Dropbox/Research/InformedSources/Replication/Analysis
local datdir /Users/byrned/Dropbox/Research/InformedSources/Replication/Build/Output/

*-------------------- Figure 2: Retailer-Level Price Cycles -------------------*

* Load data
use `datdir'is_mel_p_2005_2019, clear
keep if t>=td(15sep2015) & t<=td(7nov2015)

* Dates for xlabels\
local xt1=td(15sep2015)
local xt2=td(15sep2015)+15
local xt3=td(15sep2015)+30
local xt4=td(15sep2015)+45

* Compute mean price by market, brand, date
sort bid t
collapse (mean) p c, by(bid t)

* Arrows for plots
local y1=135
local y2=135
local x1=td(26sep2015)
local x2=td(28sep2015)
local xtext1=td(22sep2015)

local y3=135
local y4=135
local x3=td(10oct2015)
local x4=td(08oct2015)
local xtext2=td(14oct2015)+0.5

* Circles and arrows for price leadership
local y5=119.5
local y6=116.75
local x5=td(27oct2015)
local x6=td(28oct2015)+0.5

local y7=119.5
local y8=118.5
local x7=td(27oct2015)
local x8=td(29oct2015)

local xtext3=td(25oct2015)+0.5

local y9=131.5
local y10=129.5
local x9=td(29oct2015)
local x10=td(31oct2015)

local y11=133.5
local y12=135.5
local x11=td(29oct2015)
local x12=td(31oct2015)

local xtext4=td(25oct2015)+0.5

* Plot example cycle from Melbourne
twoway 	(line p t if bid==1, lwidth(thin)   connect(stairstep) lcolor(gs0*0.85)  lpattern(dash)) ///
		(line p t if bid==2, lwidth(thin)   connect(stairstep) lcolor(gs0*0.7)   lpattern(shortdash) ) ///
		(line p t if bid==3, lwidth(medthick)   connect(stairstep) lcolor(gs0) lpattern(solid)) ///
		(line p t if bid==4, lwidth(thin) connect(stairstep) lcolor(gs0*0.55)  lpattern(dash_dot) ) ///
		(line p t if bid==5, lwidth(thin)   connect(stairstep) lcolor(gs0*0.4) lpattern(longdash)) ///		
		(line c t if bid==1, lwidth(medium) connect(stairstep) lcolor(gs0) lpattern(shortdash) lwidth(medthick) ///		
		ytitle("Mean Daily Station-Level Retail Price (cpl)", height(6)) ylabel(110(10)150, labsize(*0.8) grid gmin gmax) ///
		xtitle("Date", height(6)) ///
		xlabel(`xt1' `" "Sep 15"  "2015" "' `xt2' `" "Oct 1"  "2015" "' `xt3' `" "Oct 15"  "2015" "' `xt4' `" "Nov 1"  "2015" "', labsize(*0.7)) ///		
		plotregion(margin(zero) style(none) fcolor(white)) graphregion(color(white)) bgcolor(white) ///
		legend(order(1 2 3 4 5 6) ring(0) size(*0.75) position(12) symx(*0.5) region(lwidth(*0.05)) rows(1) ///
		label(1 "BP") label(2 "Caltex") label(3 "Coles") label(4 "Woolworths") label(5 "7-Eleven") label(6 "Wholesale" "TGP")))	///
		(pcarrowi `y1' `x1' `y2' `x2', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(135 `xtext1' "Restoration" "phase", justification(right) size(*0.85)))	///
		(pcarrowi `y3' `x3' `y4' `x4', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(135 `xtext2' "Undercutting" "phase", justification(left) size(*0.85))) ///
		(scatter p t if (bid==3 | bid==4) & t==td(29oct2015), mcolor(black%15) msize(*1.1) msymbol(circle)) ///
		(scatter p t if (bid==1 | bid==2 | bid==3 | bid==4 | bid==5) & t==td(30oct2015), mcolor(black%15) msize(*1.1) msymbol(circle)) ///
		(pcarrowi `y5' `x5' `y6' `x6', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(122 `xtext3' "Restoration" "price {bf:signals}", justification(center) size(*0.65))) ///
		(pcarrowi `y7' `x7' `y8' `x8', color(black) lwidth(*1) barbsize(1) msize(2)) ///
		(pcarrowi `y5' `x5' `y6' `x6', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(132.7 `xtext4' "Restoration" "{bf:consolidation}", justification(right) size(*0.65))) ///
		(pcarrowi `y9' `x9' `y10' `x10', color(black) lwidth(*1) barbsize(1) msize(2)) ///
		(pcarrowi `y11' `x11' `y12' `x12', color(black) lwidth(*1) barbsize(1) msize(2))
graph export Output/fig2_example.pdf, as(pdf) replace

